/**
 * @file STL_Linux.h
 * @author Derek Liu (yjkhtddx@sina.com)
 * @brief 
 * @version 0.1
 * @date 2020-10-19
 * 
 * @copyright Copyright Sci-Tech Laboratories (c) 2020
 * 
 */

#ifndef _STL_LINUX_H_
#define _STL_LINUX_H_

#include <string>

namespace STL
{
    typedef struct MEMPACKED //定义一个mem occupy的结构体
    {
        char MemTotalName[20]; //定义一个char类型的数组名name有20个元素
        unsigned long MemTotal;
        char MemAvailableName[20];
        unsigned long MemAvailable;
        char MemFreeName[20];
        unsigned long MemFree;
        char BuffersName[20];
        unsigned long Buffers;
        char CachedName[20];
        unsigned long Cached;
        char SwapCachedName[20];
        unsigned long SwapCached;
    } MEM_OCCUPY;

    //proc/stat文件结构
    //cpu  633666 46912 249878 176813696 782884 2859 19625 0
    //cpu0 633666 46912 249878 176813696 782884 2859 19625 0
    //intr 5812844
    //ctxt 265816063
    //btime 1455203832
    //processes 596625
    //procs_running 1
    //procs_blocked 0

    typedef struct CPUPACKED //定义一个cpu occupy的结构体
    {
        char name[20];       //定义一个char类型的数组名name有20个元素
        unsigned int user;   //定义一个无符号的int类型的user
        unsigned int nice;   //定义一个无符号的int类型的nice
        unsigned int system; //定义一个无符号的int类型的system
        unsigned int idle;   //定义一个无符号的int类型的idle
        unsigned int lowait;
        unsigned int irq;
        unsigned int softirq;
    } CPU_OCCUPY;

    typedef struct System_Info_t
    {
        uint64_t uptime;
        float cpu_percent;
        float mem_percent;
        uint64_t mem_used;
        uint64_t mem_free;
        uint64_t mem_total;
        float load1;
        float load5;
        float load15;
    } System_Info;

    std::string getCwd();
    int get_mac_addr(const char *name, char *addr);
    int get_local_ip(const char *name, char *ip);

    void get_memoccupy(MEM_OCCUPY *mem);  //对无类型get函数含有一个形参结构体类弄的指针O
    int get_cpuoccupy(CPU_OCCUPY *cpust); //对无类型get函数含有一个形参结构体类弄的指针O
    void cal_cpuoccupy(CPU_OCCUPY *o, CPU_OCCUPY *n);

    int get_cpu_count();
    int get_top_parse_info(System_Info *info);
    
    void stl_daemonlock();

} // namespace STL

#endif //_STL_LINUX_H_
